﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CommonLib;

namespace QueueMgrUtil
{
    public class QueueManager
    {
        public static BlockReadQueue<QueueWorkItem> WorkItemsQueue = new BlockReadQueue<QueueWorkItem>();


        public static bool isWorkItemQueuPresent()
        {
            if (WorkItemsQueue == null) return false;
              return true;
        }

        /// <summary>
        /// Enqueue Work Item 
        /// </summary>
        /// <param name="fetchRec"></param>
        /// <param name="rawDataFromCrawler"></param>
        /// <returns></returns>
        public static bool  EnqueueWorkItem(Object fetchRec, object rawDataFromCrawler )
        {
            if (WorkItemsQueue == null) return false;

            QueueWorkItem workItemToProcess = new QueueWorkItem(QUEUE_WORK_ITEM_TYPE.PROCESS_WORK_ITEM, fetchRec, rawDataFromCrawler );
            WorkItemsQueue.Enqueue(workItemToProcess);
            return true;
        }


        /// <summary>
        /// Enqueue End of Work Item.
        /// </summary>
        public static void EnqueueEndOfWork()
        {

            if (WorkItemsQueue == null) return;
            QueueWorkItem endoftheWork = new QueueWorkItem(QUEUE_WORK_ITEM_TYPE.PROCESS_END, null, null);
            WorkItemsQueue.Enqueue(endoftheWork);

        }


    }
}
